package com.jwsoft.manager.core.integration.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.module.base.common.util.ApplicationContextHelper;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.core.helper.ApiModel;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.IrsSyncTypeEnum;
import com.jwsoft.manager.common.enums.SchoolCategoryEnum;
import com.jwsoft.manager.common.enums.SourceTypeEnum;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.common.AreaControlVO;
import com.jwsoft.manager.common.vo.dygx.DyJzzVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseHoldInterfaceVO;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.BatchCreateVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreKeyVO;
import com.jwsoft.manager.common.vo.eduSyncIrs.EduSyncIrsBatchVO;
import com.jwsoft.manager.common.vo.eduSyncIrs.EduSyncIrsKeyVO;
import com.jwsoft.manager.common.vo.eduSyncIrs.EduSyncIrsVO;
import com.jwsoft.manager.common.vo.individuation.*;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.BatchCallSjgxIntegration;
import com.jwsoft.manager.core.integration.EduStudentEnrollIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.integration.common.DygxIntegration;
import com.jwsoft.manager.core.util.AddressUtil;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 大数据批量比对
 * **/
@ApiService(funcCode = "batchCallSjgx", title = "批量大数据批量比对")
@Slf4j
public class BatchCallSjgxIntegrationImpl implements BatchCallSjgxIntegration {
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduStudentEnrollIntegration eduStudentEnrollIntegration;
    @Autowired
    private RedisHelper redisHelper;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;
    @Autowired
    private EduSyncIrsService eduSyncIrsService;
    @Autowired
    private CommonIntegration commonIntegration;
    @Autowired
    private EduHouseholdService eduHouseholdService;
    @Autowired
    private EduAddressService eduAddressService;
    @Autowired
    private EduSocialSecurityService eduSocialSecurityService;
    @Autowired
    private EduHouseDetailService eduHouseDetailService;
    @Autowired
    private EduHouseService eduHouseService;
    @Autowired
    private DygxIntegration dygxIntegration;
    @Autowired
    private DictIntegration dictIntegration;
    @Autowired
    private EduLivePlaceService eduLivePlaceService;
    @Autowired
    private EduAddressTreeService eduAddressTreeService;
    private final String createBatchBeforeCatch = "task:createBatchBeforeCatch";
    @Override
    @OpApi(funcCode = "batchCallSjgx0001", title = "房产批量数据获取", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void saveBatchHouseInterfaceFree(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getFc";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getYear, year)
                .eq(EduStudentEnrollPre::getHouseSyncFlag, BoolEnum.FALSE.getType());
        PageHelper.startPage(1,2000);
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("saveHouseInterfaceData",vo.getAreaCode());
        redisHelper.set(redisKey,"房产批量获取正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                saveList.forEach(
                item -> {
                    Boolean flag=eduStudentEnrollIntegration.checkEnroll(item.getIdcard(),item.getYear());
                    if(flag){
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getHouseSyncFlag,BoolEnum.TRUE.getType())
                                .set(EduStudentEnrollPre::getHouseSyncRemark,"已报名，不再调用");
                        eduStudentEnrollPreService.update(updateWrapper);

                    }else {
                        try {
                            List<String> allIdcardList = new ArrayList<>();
                            List<String> allNameList = new ArrayList<>();
                            allIdcardList.add(item.getIdcard());
                            allNameList.add(item.getFullName());
                            boolean oneFlag=false;
                            if (!ObjectUtils.isEmpty(item.getFatherIdcard())) {
                                allIdcardList.add(item.getFatherIdcard());
                                allNameList.add(item.getFatherName());
                            }else{
                                oneFlag=true;
                            }
                            if (!ObjectUtils.isEmpty(item.getMotherIdcard())) {
                                allIdcardList.add(item.getMotherIdcard());
                                allNameList.add(item.getMotherName());
                            }else{
                                oneFlag=true;
                            }
                            HouseInterfaceSaveVO saveVO = new HouseInterfaceSaveVO();
                            saveVO.setOneFlag(oneFlag);
                            saveVO.setIdcard(item.getIdcard());
                            saveVO.setStudentEnrollPreId(item.getStudentEnrollPreId());
                            saveVO.setName(item.getFullName());
                            saveVO.setFatherIdcard(item.getFatherIdcard());
                            saveVO.setFatherName(item.getFatherName());
                            saveVO.setMotherIdcard(item.getMotherIdcard());
                            saveVO.setMotherName(item.getMotherName());
                            saveVO.setAllIdcardList(allIdcardList);
                            saveVO.setAllNameList(allNameList);
                            saveVO.setAreaCode(item.getAreaCode());
                            saveVO.setReqIp(vo.getReqIp());
                            apiModel.getMethod().invoke(bean, saveVO);
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getHouseSyncFlag,BoolEnum.TRUE.getType())
                                    .set(EduStudentEnrollPre::getBeforeFlag,BoolEnum.FALSE.getType())
                                    .set(EduStudentEnrollPre::getHouseSyncRemark,"调用成功");
                            EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                            if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                                //人工处理过的数据，不重新比对
                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                        .set(EduStudentEnrollPre::getHouseId,null);
                            }
                            eduStudentEnrollPreService.update(updateWrapper);
                            if(StringUtils.isNotBlank(item.getIdcard())){
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreFc(item.getIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                            }
                            if(StringUtils.isNotBlank(item.getFatherIdcard())){
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreFc(item.getFatherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                            }
                            if(StringUtils.isNotBlank(item.getMotherIdcard())){
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreFc(item.getMotherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                            }
                            eduEnrollClearCacheHelper.clearCachePreBefore(item.getStudentEnrollPreId());
                        } catch (AppException e){
                            log.error("大数据房产获取异常："+e.getMsg());
                            String msg=e.getMsg();
                            if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                                msg=msg.substring(0,200);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getHouseSyncFlag,"2")
                                    .set(EduStudentEnrollPre::getHouseSyncRemark,msg);
                            EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                            if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                                //人工处理过的数据，不重新比对
                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                        .set(EduStudentEnrollPre::getHouseId,null);
                            }
                            eduStudentEnrollPreService.update(updateWrapper);
                        }catch (InvocationTargetException e ){
                            String msg=e.getMessage();
                            try{
                                AppException exception= (AppException) e.getTargetException();
                                msg=exception.getMsg();
                            }catch (Exception ex){
                                msg="大数据房产获取异常："+ex.getMessage();
                            }
                            log.error("大数据房产获取异常："+e.getMessage());
                            if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                                msg=msg.substring(0,200);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getHouseSyncFlag,"2")
                                    .set(EduStudentEnrollPre::getHouseSyncRemark,msg);
                            EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                            if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                                //人工处理过的数据，不重新比对
                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                        .set(EduStudentEnrollPre::getHouseId,null);
                            }
                            eduStudentEnrollPreService.update(updateWrapper);
                        }catch (Exception e) {
                            log.error("大数据房产获取异常："+e.getMessage());
                            String msg=e.getMessage();
                            if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                                msg=msg.substring(0,200);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getHouseSyncFlag,"2")
                                    .set(EduStudentEnrollPre::getHouseSyncRemark,msg);
                            EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                            if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                                //人工处理过的数据，不重新比对
                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                        .set(EduStudentEnrollPre::getHouseId,null);
                            }
                            eduStudentEnrollPreService.update(updateWrapper);
                        }
                    }
                });

            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        } catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }finally {
            redisHelper.del(redisKey);
        }

    }
    @Override
    @OpApi(funcCode = "batchCallSjgx0002", title = "户籍批量数据获取", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void saveBatchHouseholdInterfaceFree(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getHj";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        PageHelper.startPage(1,2000);
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getYear, year)
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getHouseholdSyncFlag, BoolEnum.FALSE.getType());
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        if(vo.getLocalFlag()==null){
            vo.setLocalFlag(false);
        }
        boolean syncFlag=false;
        if(!vo.getLocalFlag()){
            CommonVO commonIrsAsyncVO = new CommonVO();
            commonIrsAsyncVO.setParamKey("irs_async");
            commonIrsAsyncVO.setAreaCode(vo.getAreaCode());
            String irsAsync = commonIntegration.getValueByKeyAndArea(commonIrsAsyncVO);
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(irsAsync) || "true".equalsIgnoreCase(irsAsync)) {
                syncFlag=true;
            }
        }
        final boolean finalFlag=syncFlag;
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("saveHouseHoldData",vo.getAreaCode());
        redisHelper.set(redisKey,"户籍批量获取正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {

                saveList.forEach(
                item -> {
                    try {
                        Boolean flag = eduStudentEnrollIntegration.checkEnroll(item.getIdcard(), item.getYear());
                        if (flag) {
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getHouseholdSyncFlag, BoolEnum.TRUE.getType())
                                    .set(EduStudentEnrollPre::getHouseholdSyncRemark, "已报名，不再调用");
                            eduStudentEnrollPreService.update(updateWrapper);
                        } else {
                            HouseHoldSaveVO saveVO = new HouseHoldSaveVO();
                            saveVO.setIdcard(item.getIdcard());
                            saveVO.setStudentEnrollPreId(item.getStudentEnrollPreId());
                            saveVO.setLocalFlag(vo.getLocalFlag());
                            saveVO.setReqIp(vo.getReqIp());
                            apiModel.getMethod().invoke(bean, saveVO);
                            if("330783".equalsIgnoreCase(item.getAreaCode())){
                                try {
                                    //东阳还需要获取父母户口信息
                                    if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                        HouseHoldSaveVO savefqVO = new HouseHoldSaveVO();
                                        savefqVO.setIdcard(item.getFatherIdcard());
                                        savefqVO.setLocalFlag(vo.getLocalFlag());
                                        savefqVO.setStudentEnrollPreId(item.getStudentEnrollPreId());
                                        savefqVO.setReqIp(vo.getReqIp());
                                        apiModel.getMethod().invoke(bean, savefqVO);
                                    }
                                    if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                        HouseHoldSaveVO saveMqVO = new HouseHoldSaveVO();
                                        saveMqVO.setIdcard(item.getMotherIdcard());
                                        saveMqVO.setLocalFlag(vo.getLocalFlag());
                                        saveMqVO.setStudentEnrollPreId(item.getStudentEnrollPreId());
                                        saveMqVO.setReqIp(vo.getReqIp());
                                        apiModel.getMethod().invoke(bean, saveMqVO);
                                    }
                                }catch (Exception e){
                                    log.error("获取父母户口信息发生异常",e);
                                }
                            }

                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getHouseholdSyncFlag, finalFlag ? "3" : "1")
                                    .set(EduStudentEnrollPre::getBeforeFlag, BoolEnum.FALSE.getType())
                                    .set(EduStudentEnrollPre::getHouseholdSyncRemark, finalFlag ? "同步中" : "调用成功");
                            EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                            if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                                //人工处理过的数据，不重新比对
                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                        .set(EduStudentEnrollPre::getHouseholdId,null);
                            }
                            eduStudentEnrollPreService.update(updateWrapper);
                            if (StringUtils.isNotBlank(item.getIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                            }
                            eduEnrollClearCacheHelper.clearCachePreBefore(item.getStudentEnrollPreId());
                        }
                    }  catch (AppException e){
                        log.error("大数据户籍获取异常："+e.getMsg());
                        String msg=e.getMsg();
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getHouseholdSyncFlag,"2")
                                .set(EduStudentEnrollPre::getHouseholdSyncRemark,msg);
                        EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                        if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                            //人工处理过的数据，不重新比对
                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                    .set(EduStudentEnrollPre::getHouseholdId,null);
                        }
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (InvocationTargetException e ){
                        String msg=e.getMessage();
                        try{
                            AppException exception= (AppException) e.getTargetException();
                            msg=exception.getMsg();
                        }catch (Exception ex){
                            msg="大数据户籍获取异常："+ex.getMessage();
                        }
                        log.error("大数据户籍获取异常："+e.getMessage());
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getHouseholdSyncFlag,"2")
                                .set(EduStudentEnrollPre::getHouseholdSyncRemark,msg);
                        EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                        if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                            //人工处理过的数据，不重新比对
                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                    .set(EduStudentEnrollPre::getHouseholdId,null);
                        }
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (Exception e) {
                        log.error("大数据户籍获取异常："+e.getMessage());
                        String msg=e.getMessage();
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getHouseholdSyncFlag,"2")
                                .set(EduStudentEnrollPre::getHouseholdSyncRemark,msg);
                        EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(item.getStudentEnrollPreId());
                        if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                            //人工处理过的数据，不重新比对
                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                                    .set(EduStudentEnrollPre::getHouseholdId,null);
                        }
                        eduStudentEnrollPreService.update(updateWrapper);
                    }
                });
            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }finally {
            redisHelper.del(redisKey);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0011", title = "将东阳教育irs转发平台上的户籍同步下来", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void syncBatchHousehouldByLocal(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getLocalHj";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("IRS_LOCAL0001");
        commonVO.setAreaCode(vo.getAreaCode());
        String url = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(url)) {
            throw new AppException("请先在系统参数表中设置IRS_LOCAL0001（本地Irs服务健康检查接口地址）");
        }

        //判断服务器是否联通
        try {
            HttpUtil.get(url,2000);
        }catch (Exception e){
            log.error("本地的irs转发服务不在联通状态");
            return;
        }
        //调用发送接口
        CommonVO commonSendVO = new CommonVO();
        commonSendVO.setParamKey("IRS_LOCAL0003");
        commonSendVO.setAreaCode(vo.getAreaCode());
        String sendUrl = commonIntegration.getValueByKeyAndArea(commonSendVO);
        if (StringUtils.isBlank(sendUrl)) {
            throw new AppException("请先在系统参数表中设置IRS_LOCAL0003（本地Irs服务根据id获取同步情况数据）");
        }
        QueryWrapper<EduSyncIrs> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(EduSyncIrs::getSyncType, IrsSyncTypeEnum.hj.getType())
                .eq(EduSyncIrs::getSendFlag,BoolEnum.TRUE.getType())
                .eq(EduSyncIrs::getNewFlag,BoolEnum.TRUE.getType())
                .eq(EduSyncIrs::getSyncStatus,BoolEnum.FALSE.getType())
                .eq(EduSyncIrs::getYear,year).orderByAsc(EduSyncIrs::getSendTime);
        PageHelper.startPage(1,2000);
        List<EduSyncIrs> syncIrsList=eduSyncIrsService.list(queryWrapper);
        PageInfo<EduSyncIrs> pageInfo=new PageInfo<>(syncIrsList);
        if(!CollectionUtils.isEmpty(pageInfo.getList())){
            redisHelper.set(redisKey,"户籍本地irs转发批量获取正在执行中",1800);
            for(EduSyncIrs irs:pageInfo.getList()){
                EduSyncIrsKeyVO eduSyncIrsKeyVO=new EduSyncIrsKeyVO();
                eduSyncIrsKeyVO.setIrsSyncId(irs.getIrsSyncId());
                try {
                    String body=HttpUtil.post(sendUrl, JSON.toJSONString(eduSyncIrsKeyVO),2000);
                    if("IRSGX0003".equalsIgnoreCase(irs.getIrsCode())){
                        syncHj(body);
                    }

                }catch (Exception e){
                    log.error("本地的irs转发服务不在联通状态");
                    redisHelper.del(redisKey);
                    break;
                }finally {
                    redisHelper.del(redisKey);
                }
            }

        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0003", title = "网签批量数据获取", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void saveBatchNetSignInterfaceFree(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getWq";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        PageHelper.startPage(1,2000);
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getYear, year)
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getNetsignSyncFlag, BoolEnum.FALSE.getType());
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("saveNetsignInterfaceData",vo.getAreaCode());
        redisHelper.set(redisKey,"网签批量获取正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {

                for(EduStudentEnrollPre item:saveList){
                    try {
                        Boolean flag = eduStudentEnrollIntegration.checkEnroll(item.getIdcard(), item.getYear());
                        if (flag) {
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getNetsignSyncFlag, BoolEnum.TRUE.getType())
                                    .set(EduStudentEnrollPre::getNetsignSyncFlag, "已报名，不再调用");
                            eduStudentEnrollPreService.update(updateWrapper);
                        } else {
                            NetsignSaveVO saveVO = new NetsignSaveVO();
                            saveVO.setIdcard(item.getIdcard());
                            saveVO.setReplaceFlag(true);
                            apiModel.getMethod().invoke(bean, saveVO);
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                saveVO.setIdcard(item.getFatherIdcard());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }

                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                saveVO.setIdcard(item.getMotherIdcard());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getNetsignSyncFlag, "1")
                                    .set(EduStudentEnrollPre::getNetsignSyncRemark, "调用成功");
                            eduStudentEnrollPreService.update(updateWrapper);
                            if (StringUtils.isNotBlank(item.getIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(item.getIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(item.getFatherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreWq(item.getMotherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                            }
                            eduEnrollClearCacheHelper.clearCachePreBefore(item.getStudentEnrollPreId());
                        }
                    }catch (AppException e){
                        log.error("大数据网签获取异常："+e.getMsg());
                        String msg = e.getMsg();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getNetsignSyncFlag, "2")
                                .set(EduStudentEnrollPre::getNetsignSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    } catch (InvocationTargetException e ){
                        String msg=e.getMessage();
                        try{
                            AppException exception= (AppException) e.getTargetException();
                            msg=exception.getMsg();
                        }catch (Exception ex){
                            msg="大数据网签获取异常："+ex.getMessage();
                        }
                        log.error("大数据网签获取异常："+e.getMessage());
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getNetsignSyncFlag, "2")
                                .set(EduStudentEnrollPre::getNetsignSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (Exception e) {
                        log.error("大数据网签获取异常："+e.getMessage());
                        String msg = e.getMessage();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getNetsignSyncFlag, "2")
                                .set(EduStudentEnrollPre::getNetsignSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }
                }
            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }finally {
            redisHelper.del(redisKey);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0004", title = "参保批量数据获取", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void saveBatchCbInterfaceFree(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getSb";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getYear, year)
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getCbSyncFlag, BoolEnum.FALSE.getType());
        PageHelper.startPage(1,2000);
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("saveCbInterfaceData",vo.getAreaCode());
        redisHelper.set(redisKey,"参保批量获取正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {

                for(EduStudentEnrollPre item:saveList){
                    try {
                        Boolean flag = eduStudentEnrollIntegration.checkEnroll(item.getIdcard(), item.getYear());
                        if (flag) {
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getCbSyncFlag, BoolEnum.TRUE.getType())
                                    .set(EduStudentEnrollPre::getCbSyncRemark, "已报名，不再调用");
                            eduStudentEnrollPreService.update(updateWrapper);
                        } else {
                            CbSaveVO saveVO = new CbSaveVO();
                            saveVO.setReplaceFlag(true);
                            saveVO.setReqIp(vo.getReqIp());
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                saveVO.setIdcard(item.getFatherIdcard());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                saveVO.setIdcard(item.getMotherIdcard());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getCbSyncFlag, "1")
                                    .set(EduStudentEnrollPre::getCbSyncRemark, "调用成功");
                            eduStudentEnrollPreService.update(updateWrapper);
                            if (StringUtils.isNotBlank(item.getIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreSb(item.getIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreSb(item.getFatherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreSb(item.getMotherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                            }
                            eduEnrollClearCacheHelper.clearCachePreBefore(item.getStudentEnrollPreId());
                        }
                    } catch (AppException e){
                        log.error("大数据社保获取异常："+e.getMsg());
                        String msg = e.getMsg();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getCbSyncFlag, "2")
                                .set(EduStudentEnrollPre::getCbSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (InvocationTargetException e ){
                        String msg=e.getMessage();
                        try{
                            AppException exception= (AppException) e.getTargetException();
                            msg=exception.getMsg();
                        }catch (Exception ex){
                            msg="大数据社保获取异常："+ex.getMessage();
                        }
                        log.error("大数据房社保获取异常："+e.getMessage());
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getCbSyncFlag, "2")
                                .set(EduStudentEnrollPre::getCbSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (Exception e) {
                        log.error("大数据社保获取异常："+e.getMessage());
                        String msg = e.getMessage();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getCbSyncFlag, "2")
                                .set(EduStudentEnrollPre::getCbSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }
                }
            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (Exception e ){
            throw new AppException( e.getMessage(),e);
        }finally {
            redisHelper.del(redisKey);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0012", title = "参保累计缴费批量调用", funcType = FuncTypeEnum.edit, publicFlag = BoolEnum.TRUE, savelog = false)
    public void saveBatchCbLjjfysInterfaceFree(AreaControlVO vo) {
        String redisKey = EduCache.EDU_BATCH_handle + "getCbljjf";
        if (redisHelper.hasKey(redisKey)) {
            throw new AppException("正在获取中...");
        }
        redisHelper.set(redisKey, "参保累计缴费批量调用", 1800);
     //   Integer year = checkAreaCode(vo);
        Integer year = eduHelper.thisYear();
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        QueryWrapper<EduSocialSecurity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(EduSocialSecurity::getAac147, EduSocialSecurity::getSocialSecurityId, EduSocialSecurity::getTotalErrorCnt).eq(EduSocialSecurity::getYear, year)
                .eq(EduSocialSecurity::getTotalFlag, BoolEnum.FALSE.getType())
                .eq(EduSocialSecurity::getAae140, "110")
                .eq(EduSocialSecurity::getAac008, "1")
                .eq(EduSocialSecurity::getAac031, "1");
        PageHelper.startPage(1, 500);
        List<EduSocialSecurity> list = eduSocialSecurityService.list(queryWrapper);
        PageInfo<EduSocialSecurity> pageInfo = new PageInfo<>(list);
        if (CollectionUtils.isEmpty(pageInfo.getList())) {
            QueryWrapper<EduSocialSecurity> queryErrorWrapper = new QueryWrapper<>();
            queryErrorWrapper.lambda().select(EduSocialSecurity::getAac147, EduSocialSecurity::getSocialSecurityId, EduSocialSecurity::getTotalErrorCnt).eq(EduSocialSecurity::getYear, year)
                    .eq(EduSocialSecurity::getTotalFlag, "2")
                    .eq(EduSocialSecurity::getAae140, "110")
                    .eq(EduSocialSecurity::getAac008, "1")
                    .eq(EduSocialSecurity::getAac031, "1")
                    .lt(EduSocialSecurity::getTotalErrorCnt, 3);
            PageHelper.startPage(1, 500);
            List<EduSocialSecurity> listError = eduSocialSecurityService.list(queryWrapper);
            pageInfo = new PageInfo<>(listError);
        }
        if (CollectionUtils.isEmpty(pageInfo.getList())) {
            redisHelper.del(redisKey);
            return;
        }
        for (EduSocialSecurity eduSocialSecurity : pageInfo.getList()) {
            try {
                Integer ys = dygxIntegration.getCbJfys(eduSocialSecurity.getAac147(),vo.getReqIp());
                UpdateWrapper<EduSocialSecurity> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduSocialSecurity::getSocialSecurityId, eduSocialSecurity.getSocialSecurityId())
                        .set(EduSocialSecurity::getTotal, ys)
                        .set(EduSocialSecurity::getTotalFlag, BoolEnum.TRUE.getType())
                        .set(EduSocialSecurity::getTotalTime, new Date())
                        .set(EduSocialSecurity::getTotalErrorCnt, 0)
                        .set(EduSocialSecurity::getTotalRemarks, "成功");
                eduSocialSecurityService.update(updateWrapper);
            } catch (AppException e) {
                log.error("大数据获取参保累计缴费月数异常："+e.getMsg());
                String msg = e.getMsg();
                if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }

                UpdateWrapper<EduSocialSecurity> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduSocialSecurity::getSocialSecurityId, eduSocialSecurity.getSocialSecurityId())
                        .set(EduSocialSecurity::getTotalFlag, "2")
                        .set(EduSocialSecurity::getTotalTime, new Date())
                        .set(EduSocialSecurity::getTotalErrorCnt, eduSocialSecurity.getTotalErrorCnt() == null ? 1 : eduSocialSecurity.getTotalErrorCnt() + 1)
                        .set(EduSocialSecurity::getTotalRemarks, msg);
                eduSocialSecurityService.update(updateWrapper);
            } catch (Exception e) {
                log.error("大数据获取参保累计缴费月数异常："+e.getMessage());
                String msg = e.getMessage();
                if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                    msg = msg.substring(0, 200);
                }
                UpdateWrapper<EduSocialSecurity> updateWrapper = new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduSocialSecurity::getSocialSecurityId, eduSocialSecurity.getSocialSecurityId())
                        .set(EduSocialSecurity::getTotalFlag, "2")
                        .set(EduSocialSecurity::getTotalTime, new Date())
                        .set(EduSocialSecurity::getTotalErrorCnt, eduSocialSecurity.getTotalErrorCnt() == null ? 1 : eduSocialSecurity.getTotalErrorCnt() + 1)
                        .set(EduSocialSecurity::getTotalRemarks, msg);
                eduSocialSecurityService.update(updateWrapper);
            }
        }
        redisHelper.del(redisKey);
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0005", title = "企业批量数据获取", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void saveBatchQyInterfaceFree(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getQy";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getYear, year)
                .eq(EduStudentEnrollPre::getAreaCode,vo.getAreaCode())
                .eq(EduStudentEnrollPre::getQySyncFlag, BoolEnum.FALSE.getType());
        PageHelper.startPage(1,2000);
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("saveQyInterfaceData",vo.getAreaCode());
        redisHelper.set(redisKey,"企业批量获取正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                saveList.forEach(
                item -> {
                    try {
                        Boolean flag = eduStudentEnrollIntegration.checkEnroll(item.getIdcard(), item.getYear());
                        if (flag) {
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getQySyncFlag, BoolEnum.TRUE.getType())
                                    .set(EduStudentEnrollPre::getQySyncRemark, "已报名，不再调用");
                            eduStudentEnrollPreService.update(updateWrapper);
                        } else {
                            QySaveVO saveVO = new QySaveVO();

                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                saveVO.setIdcard(item.getFatherIdcard());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                saveVO.setIdcard(item.getMotherIdcard());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getQySyncFlag, "1")
                                    .set(EduStudentEnrollPre::getQySyncRemark, "调用成功");
                            eduStudentEnrollPreService.update(updateWrapper);
                            if (StringUtils.isNotBlank(item.getIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(item.getIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(item.getFatherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreQy(item.getMotherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                            }
                            eduEnrollClearCacheHelper.clearCachePreBefore(item.getStudentEnrollPreId());
                        }
                    } catch (AppException e){
                        log.error("大数据企业获取异常："+e.getMsg());
                        String msg = e.getMsg();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getQySyncFlag, "2")
                                .set(EduStudentEnrollPre::getQySyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (InvocationTargetException e ){
                        String msg=e.getMessage();
                        try{
                            AppException exception= (AppException) e.getTargetException();
                            msg=exception.getMsg();
                        }catch (Exception ex){
                            msg="大数据企业获取异常："+ex.getMessage();
                        }
                        log.error("大数据企业获取异常："+e.getMessage());
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getQySyncFlag, "2")
                                .set(EduStudentEnrollPre::getQySyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (Exception e) {
                        log.error("大数据企业获取异常："+e.getMessage());
                        String msg = e.getMessage();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getQySyncFlag, "2")
                                .set(EduStudentEnrollPre::getQySyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }
                });
            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (Exception e ){
            throw new AppException( e.getMessage());
        }finally {
            redisHelper.del(redisKey);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0006", title = "居住证批量数据获取", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void saveBatchJzzInterfaceFree(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getJzz";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getYear, year)
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getJzzSyncFlag, BoolEnum.FALSE.getType());
        PageHelper.startPage(1,2000);
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("saveJzzInterfaceData",vo.getAreaCode());
        redisHelper.set(redisKey,"居住证批量获取正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {

                saveList.forEach(
                item -> {
                    try {
                        Boolean flag = eduStudentEnrollIntegration.checkEnroll(item.getIdcard(), item.getYear());
                        if (flag) {
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getJzzSyncFlag, BoolEnum.TRUE.getType())
                                    .set(EduStudentEnrollPre::getJzzSyncRemark, "已报名，不再调用");
                            eduStudentEnrollPreService.update(updateWrapper);
                        } else {
                            JzzSaveVO saveVO = new JzzSaveVO();
                            saveVO.setIdcard(item.getIdcard());
                            saveVO.setName(item.getFullName());
                            saveVO.setReplaceFlag(true);
                            saveVO.setLocalFlag(vo.getLocalFlag());
                            saveVO.setReqIp(vo.getReqIp());
                            apiModel.getMethod().invoke(bean, saveVO);
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                saveVO.setIdcard(item.getFatherIdcard());
                                saveVO.setName(item.getFatherName());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                saveVO.setIdcard(item.getMotherIdcard());
                                saveVO.setName(item.getMotherName());
                                apiModel.getMethod().invoke(bean, saveVO);
                            }
                            UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                            updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                    .set(EduStudentEnrollPre::getJzzSyncFlag, "1")
                                    .set(EduStudentEnrollPre::getJzzSyncRemark, vo.getLocalFlag()!=null&&!vo.getLocalFlag()?"调用成功":"调用成功本地接口");
                            eduStudentEnrollPreService.update(updateWrapper);
                            if (StringUtils.isNotBlank(item.getIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreJzz(item.getIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getFatherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreJzz(item.getFatherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getFatherIdcard());
                            }
                            if (StringUtils.isNotBlank(item.getMotherIdcard())) {
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPreJzz(item.getMotherIdcard());
                                eduEnrollClearCacheHelper.clearCacheMyEnrollPre(item.getMotherIdcard());
                            }
                            eduEnrollClearCacheHelper.clearCachePreBefore(item.getStudentEnrollPreId());
                        }
                    } catch (AppException e){
                        log.error("大数据居住证获取异常："+e.getMsg());
                        String msg = e.getMsg();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getJzzSyncFlag, "2")
                                .set(EduStudentEnrollPre::getJzzSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (InvocationTargetException e ){
                        String msg=e.getMessage();
                        try{
                            AppException exception= (AppException) e.getTargetException();
                            msg=exception.getMsg();
                        }catch (Exception ex){
                            msg="大数据居住证获取异常："+ex.getMessage();
                        }
                        log.error("大数据居住证获取异常："+e.getMessage());
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getJzzSyncFlag, "2")
                                .set(EduStudentEnrollPre::getJzzSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }catch (Exception e) {
                        log.error("大数据居住证获取异常："+e.getMessage());
                        String msg = e.getMessage();
                        if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                            msg = msg.substring(0, 200);
                        }
                        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                .set(EduStudentEnrollPre::getJzzSyncFlag, "2")
                                .set(EduStudentEnrollPre::getJzzSyncRemark, msg);
                        eduStudentEnrollPreService.update(updateWrapper);
                    }
                });
            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (Exception e ){
            throw new AppException( e.getMessage());
        }finally {
            redisHelper.del(redisKey);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0014", title = "将东阳教育irs转发平台上的居住证同步下来", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void syncBatchJzzByLocal(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getLocalJzz";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("IRS_LOCAL0001");
        commonVO.setAreaCode(vo.getAreaCode());
        String url = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(url)) {
            throw new AppException("请先在系统参数表中设置IRS_LOCAL0001（本地Irs服务健康检查接口地址）");
        }

        //判断服务器是否联通
        try {
            HttpUtil.get(url,2000);
        }catch (Exception e){
            log.error("本地的irs转发服务不在联通状态");
            return;
        }
        //调用发送接口
        CommonVO commonSendVO = new CommonVO();
        commonSendVO.setParamKey("IRS_LOCAL0003");
        commonSendVO.setAreaCode(vo.getAreaCode());
        String sendUrl = commonIntegration.getValueByKeyAndArea(commonSendVO);
        if (StringUtils.isBlank(sendUrl)) {
            throw new AppException("请先在系统参数表中设置IRS_LOCAL0003（本地Irs服务根据id获取同步情况数据）");
        }
        QueryWrapper<EduSyncIrs> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(EduSyncIrs::getSyncType, IrsSyncTypeEnum.jzz.getType())
                .eq(EduSyncIrs::getSendFlag,BoolEnum.TRUE.getType())
                .eq(EduSyncIrs::getNewFlag,BoolEnum.TRUE.getType())
                .eq(EduSyncIrs::getSyncStatus,BoolEnum.FALSE.getType())
                .eq(EduSyncIrs::getYear,year).orderByAsc(EduSyncIrs::getSendTime);
        PageHelper.startPage(1,2000);
        List<EduSyncIrs> syncIrsList=eduSyncIrsService.list(queryWrapper);
        PageInfo<EduSyncIrs> pageInfo=new PageInfo<>(syncIrsList);
        if(!CollectionUtils.isEmpty(pageInfo.getList())){
            redisHelper.set(redisKey,"居住证本地irs转发批量获取正在执行中",1800);
            for(EduSyncIrs irs:pageInfo.getList()){
                EduSyncIrsKeyVO eduSyncIrsKeyVO=new EduSyncIrsKeyVO();
                eduSyncIrsKeyVO.setIrsSyncId(irs.getIrsSyncId());
                try {
                    String body=HttpUtil.post(sendUrl, JSON.toJSONString(eduSyncIrsKeyVO),2000);
                    if("IRSGX0005".equalsIgnoreCase(irs.getIrsCode())){
                        syncJzz(body);
                    }

                }catch (Exception e){
                    log.error("本地的irs转发服务不在联通状态");
                    redisHelper.del(redisKey);
                    break;
                }finally {
                    redisHelper.del(redisKey);
                }
            }

        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0007", title = "家庭关系批量数据比对", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void getBatchFamInfoComparison(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getFamInfo";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在获取中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getHouseholdSyncFlag,BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollPre::getHouseSyncFlag,BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollPre::getYear, year)
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getFamilyFlag, BoolEnum.FALSE.getType());
        PageHelper.startPage(1,2000);
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        ApiModel apiModel=eduHelper.getEduFunc("getFamInfoComparison",vo.getAreaCode());
        redisHelper.set(redisKey,"家庭关系比对正在执行中",1800);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {

                saveList.forEach(
                        item -> {
                            try {
                                EduStudentEnrollPreKeyVO saveVO = new EduStudentEnrollPreKeyVO();
                                saveVO.setStudentEnrollPreId(item.getStudentEnrollPreId());
                                apiModel.getMethod().invoke(bean, saveVO);
                            } catch (AppException e){
                                log.error("大数据家庭关系比对异常："+e.getMsg());
                                String msg = e.getMsg();
                                if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                                    msg = msg.substring(0, 200);
                                }
                                UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                        .set(EduStudentEnrollPre::getFamilyFlag, "4")
                                        .set(EduStudentEnrollPre::getFamilyRemark, msg);
                                eduStudentEnrollPreService.update(updateWrapper);
                            }catch (InvocationTargetException e ){
                                String msg=e.getMessage();
                                try{
                                    AppException exception= (AppException) e.getTargetException();
                                    msg=exception.getMsg();
                                }catch (Exception ex){
                                    msg="大数据家庭关系比对异常："+ex.getMessage();
                                }
                                log.error("大数据家庭关系比对异常："+e.getMessage());
                                if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                                    msg=msg.substring(0,200);
                                }
                                UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                        .set(EduStudentEnrollPre::getFamilyFlag, "4")
                                        .set(EduStudentEnrollPre::getFamilyRemark, msg);
                                eduStudentEnrollPreService.update(updateWrapper);
                            }catch (Exception e) {
                                log.error("大数据家庭关系比对异常："+e.getMessage());
                                String msg = e.getMessage();
                                if (StringUtils.isNotBlank(msg) && msg.length() > 300) {
                                    msg = msg.substring(0, 200);
                                }
                                UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
                                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, item.getStudentEnrollPreId())
                                        .set(EduStudentEnrollPre::getFamilyFlag, "4")
                                        .set(EduStudentEnrollPre::getFamilyRemark, msg);
                                eduStudentEnrollPreService.update(updateWrapper);
                            }
                        });
            }else {
                throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (Exception e ){
            throw new AppException( e.getMessage());
        }finally {
            redisHelper.del(redisKey);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0009", title = "批量预报名数据生成", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void createBatch(AreaControlVO vo) {
        if (redisHelper.hasKey(createBatchBeforeCatch)) {
            throw new AppException("正在批量生成预报名数据中...");
        }
        redisHelper.set(createBatchBeforeCatch, "1", 1800);
        String areaCode=vo.getAreaCode();
        if(StringUtils.isBlank(areaCode)){
            areaCode=eduHelper.thisAreaCode();
        }
        ApiModel apiModel=eduHelper.getEduFunc("createBatch",areaCode);
        try {
            Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
            if (null != bean) {
                BatchCreateVO batchCreateVO=new BatchCreateVO();
                batchCreateVO.setBeforeFlag("0");
                batchCreateVO.setAreaCode(areaCode);
                apiModel.getMethod().invoke(bean, batchCreateVO);
            }else {
                throw new AppException("未查询到方法");
            }
        }catch (AppException e ){
            throw e;
        }catch (InvocationTargetException e ){
            try{
                AppException exception= (AppException) e.getTargetException();
                throw new AppException(exception.getMsg(),e.getTargetException());
            }catch (Exception ex){
                throw new AppException(e.getCause().getMessage(),e.getTargetException());
            }

        }catch (Exception e ){
            throw new AppException( e.getMessage());
        }finally {
            redisHelper.del(createBatchBeforeCatch);
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0010", title = "数据发送到东阳教育irs转发平台", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void sendLocalIrsTaskData(AreaControlVO vo) {
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("IRS_LOCAL0001");
        commonVO.setAreaCode(vo.getAreaCode());
        String url = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(url)) {
            throw new AppException("请先在系统参数表中设置IRS_LOCAL0001（本地Irs服务健康检查接口地址）");
        }

        //判断服务器是否联通
        try {
            HttpUtil.get(url,2000);
        }catch (Exception e){
            log.info("本地的irs转发服务不在联通状态");
            return;
        }
        //调用发送接口
        CommonVO commonSendVO = new CommonVO();
        commonSendVO.setParamKey("IRS_LOCAL0002");
        commonSendVO.setAreaCode(vo.getAreaCode());
        String sendUrl = commonIntegration.getValueByKeyAndArea(commonSendVO);
        if (StringUtils.isBlank(sendUrl)) {
            throw new AppException("请先在系统参数表中设置IRS_LOCAL0002（本地Irs服务接受待发送数据接口地址）");
        }
        //待发送数据处理
        PageHelper.startPage(1,500);
        QueryWrapper<EduSyncIrs> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(EduSyncIrs::getSendFlag,BoolEnum.FALSE.getType())
            .eq(EduSyncIrs::getNewFlag,BoolEnum.TRUE.getType())
                .eq(StringUtils.isNotBlank(vo.getSyncType()),EduSyncIrs::getSyncType,vo.getSyncType())
        .orderByAsc(EduSyncIrs::getReqTime);
        List<EduSyncIrs> list=eduSyncIrsService.list(queryWrapper);
        PageInfo<EduSyncIrs> pageInfo=new PageInfo<>(list);
        if(!CollectionUtils.isEmpty(pageInfo.getList())){
            List<EduSyncIrsVO> voList= Convert.toList(EduSyncIrsVO.class,pageInfo.getList());
            EduSyncIrsBatchVO eduSyncIrsBatchVO=new EduSyncIrsBatchVO();
            eduSyncIrsBatchVO.setList(voList);

            try {
                String body=HttpUtil.post(sendUrl, JSON.toJSONString(eduSyncIrsBatchVO),20000);
                setSyncIrs(body,pageInfo.getList());
            }catch (Exception e){
                log.info("本地的irs转发服务不在联通状态");
                return;
            }
        }

        //发送错误数据处理 错误次数小于等于3的数据可自动发送
        PageHelper.startPage(1,500);
        QueryWrapper<EduSyncIrs> queryWrapperErr=new QueryWrapper<>();
        queryWrapperErr.lambda().eq(EduSyncIrs::getSendFlag,"2")
                .eq(EduSyncIrs::getNewFlag,BoolEnum.TRUE.getType())
                .lt(EduSyncIrs::getSendErrorCnt,3)
                .eq(StringUtils.isNotBlank(vo.getSyncType()),EduSyncIrs::getSyncType,vo.getSyncType());
        List<EduSyncIrs> listErr=eduSyncIrsService.list(queryWrapperErr);
        if(CollectionUtils.isEmpty(listErr)){
            return;
        }
        PageInfo<EduSyncIrs> pageInfoErr=new PageInfo<>(listErr);
        List<EduSyncIrsVO> voErrList= Convert.toList(EduSyncIrsVO.class,pageInfoErr.getList());
        EduSyncIrsBatchVO eduSyncIrsBatchErrVO=new EduSyncIrsBatchVO();
        eduSyncIrsBatchErrVO.setList(voErrList);
        //调用发送接口
        try {
            String bodyErr = HttpUtil.post(sendUrl, JSON.toJSONString(eduSyncIrsBatchErrVO), 20000);
            setSyncIrs(bodyErr, pageInfoErr.getList());
        }catch (Exception e){
            log.info("本地的irs转发服务不在联通状态");
            return;
        }
    }

    @Override
    @OpApi(funcCode = "batchCallSjgx0013", title = "大数据比对房户一致", funcType = FuncTypeEnum.edit,publicFlag = BoolEnum.TRUE,savelog = false)
    public void fhyzTask(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getFcHjYz";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在比对中...");
        }
        //Integer year=checkAreaCode(vo);//报名期间也可以批量获取，如报名后不能获取，请关闭定时任务
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        }else{
            areaList.add(vo.getAreaCode());
        }
        //只有房产已获取、户籍已获取，并且比对类型不是人工核对，未比对的数据才能进行批量比对
        QueryWrapper<EduStudentEnrollPre> studentEnrollPreQueryWrapper = new QueryWrapper<>();
        studentEnrollPreQueryWrapper
                .lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,
                EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFullName,
                EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getFatherName,
                EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getMotherName,
                EduStudentEnrollPre::getAreaCode)
                .eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .in(EduStudentEnrollPre::getAreaCode,areaList)
                .eq(EduStudentEnrollPre::getYear, year)
                .eq(EduStudentEnrollPre::getHouseholdSyncFlag,BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollPre::getHouseSyncFlag,BoolEnum.TRUE.getType())
                .ne(EduStudentEnrollPre::getConsistentType,"2")
                .eq(EduStudentEnrollPre::getConsistentFlag, BoolEnum.FALSE.getType());
        PageHelper.startPage(1,2000);
        List<EduStudentEnrollPre> list =
                eduStudentEnrollPreService.list(studentEnrollPreQueryWrapper);
        PageInfo<EduStudentEnrollPre> pageInfo=new PageInfo<>(list);
        if(CollectionUtils.isEmpty(pageInfo.getList())){
            return;
        }
        List<EduStudentEnrollPre> saveList=pageInfo.getList();
        redisHelper.set(redisKey,"房户一致性比对正在执行中",600);
        for(EduStudentEnrollPre pre:saveList){
            try {
                fhyzTaskDg(pre);
            }catch (Exception e){
                e.printStackTrace();
            }



        }
        redisHelper.del(redisKey);

    }

    @Override
    public void fhyzTaskDg(EduStudentEnrollPre pre) {
        Integer year=eduHelper.thisYear();
        List<String> idcardList = new ArrayList<>();
        idcardList.add(pre.getIdcard());
        if (StringUtils.isNotBlank(pre.getFatherIdcard())) {
            idcardList.add(pre.getFatherIdcard());
        }
        if (StringUtils.isNotBlank(pre.getMotherIdcard())) {
            idcardList.add(pre.getMotherIdcard());
        }
        //获取户籍信息
        LambdaQueryWrapper<EduHousehold> householdLambdaQueryWrapper = new LambdaQueryWrapper<>();
        householdLambdaQueryWrapper.select(EduHousehold::getHouseholdId, EduHousehold::getAddress, EduHousehold::getAddressId).eq(EduHousehold::getIdcard, pre.getIdcard())
                .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType())
                .eq(EduHousehold::getYear, year)
                .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType());
        EduHousehold household = eduHouseholdService.getOne(householdLambdaQueryWrapper, false);
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, pre.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getConsistentType, "1").set(EduStudentEnrollPre::getConsistentTime, new Date());
        if (household == null) {
            //户籍不存在，房户一致比对不通过
            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "2")
                    .set(EduStudentEnrollPre::getHouseholdId,null)
                    .set(EduStudentEnrollPre::getHouseId,null)
                    .set(EduStudentEnrollPre::getBeforeFlag,"0")
                    .set(EduStudentEnrollPre::getConsistentRemarks, "审核通过的有效户籍不存在，比对不通过");
            eduStudentEnrollPreService.update(updateWrapper);
            pre.setConsistentFlag("2");
            return;
        } else {
            updateWrapper.lambda().set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId());
            String householdAddress = household.getAddress();
            String addressId = household.getAddressId();
            if (StringUtils.isBlank(addressId)) {
                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "2")
                        .set(EduStudentEnrollPre::getHouseholdId,null)
                        .set(EduStudentEnrollPre::getHouseId,null)
                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                        .set(EduStudentEnrollPre::getConsistentRemarks, "户籍地址未进入地址库，比对不通过");
                eduStudentEnrollPreService.update(updateWrapper);
                pre.setConsistentFlag("2");
                return;
            }
            //获取房产信息
            QueryWrapper<EduHouseDetail> oldDetailQueryWrapper = new QueryWrapper<>();
            oldDetailQueryWrapper
                    .lambda()
                    .in(EduHouseDetail::getIdcard, idcardList)
                    .eq(EduHouseDetail::getYear, year)
                    .select(EduHouseDetail::getHouseId);
            List<EduHouseDetail> detailList = eduHouseDetailService.list(oldDetailQueryWrapper);
            if (CollectionUtils.isEmpty(detailList)) {
                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "2")
                        .set(EduStudentEnrollPre::getHouseholdId,null)
                        .set(EduStudentEnrollPre::getHouseId,null)
                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                        .set(EduStudentEnrollPre::getConsistentRemarks, "未找到名下房产信息，比对不通过");
                eduStudentEnrollPreService.update(updateWrapper);
                pre.setConsistentFlag("2");
                return;
            }
            List<String> houseIdList = detailList.stream().map(EduHouseDetail::getHouseId).distinct().collect(Collectors.toList());

            QueryWrapper<EduHouse> eduHouseQueryWrapper = new QueryWrapper<>();
            eduHouseQueryWrapper.lambda().select(EduHouse::getHouseId, EduHouse::getAddress, EduHouse::getAddressId).in(EduHouse::getHouseId, houseIdList).eq(EduHouse::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduHouse::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHouse::getYear, year);
            List<EduHouse> houseList = eduHouseService.list(eduHouseQueryWrapper);
            if (CollectionUtils.isEmpty(houseList)) {
                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "2")
                        .set(EduStudentEnrollPre::getHouseholdId,null)
                        .set(EduStudentEnrollPre::getHouseId,null)
                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                        .set(EduStudentEnrollPre::getConsistentRemarks, "未找到有效且审核通过房产信息，比对不通过");
                eduStudentEnrollPreService.update(updateWrapper);
                pre.setConsistentFlag("2");
                return;
            }
            //第一轮判断addressId是否一致
            boolean fhyz = false;
            for (EduHouse house : houseList) {
                if (house.getAddressId().equalsIgnoreCase(addressId)) {
                    fhyz = true;
                    updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                            .set(EduStudentEnrollPre::getHouseId,house.getHouseId())
                            .set(EduStudentEnrollPre::getBeforeFlag,"0")
                            .set(EduStudentEnrollPre::getHouseholdId,household.getHouseholdId())
                            .set(EduStudentEnrollPre::getConsistentRemarks, "地址一致，比对通过");
                    eduStudentEnrollPreService.update(updateWrapper);
                    break;
                }
            }
            if (fhyz) {
                pre.setConsistentFlag("1");
                return;
            }
            //第二轮判断根据treeId
            EduAddress houseHoldAdd = eduAddressService.getById(addressId);
            if (houseHoldAdd == null) {
                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "2")
                        .set(EduStudentEnrollPre::getHouseholdId,null)
                        .set(EduStudentEnrollPre::getHouseId,null)
                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                        .set(EduStudentEnrollPre::getConsistentRemarks, "户籍地址对应地址池不存在，比对不通过");
                eduStudentEnrollPreService.update(updateWrapper);
                pre.setConsistentFlag("2");
                return;
            }
            Long addressTreeId = houseHoldAdd.getAddressTreeId();
            String householdStr=houseHoldAdd.getParentPath();//户籍的标准化地址
            String bzhHousehold= houseHoldAdd.getAddressName();
            String haoHousehold= houseHoldAdd.getAddressName();
            if(StringUtils.isNotBlank(householdStr)){
                //剔除中间路xxx号
                haoHousehold=AddressUtil.extractHao(householdStr);
                haoHousehold=AddressUtil.extractBeforeFirstDigit(haoHousehold);
                //获取数字前面的字符串
                bzhHousehold=AddressUtil.extractBeforeFirstDigit(householdStr);
            }

            for (EduHouse house : houseList) {
                if (StringUtils.isNotBlank(house.getAddressId())) {
                    EduAddress houseAdd = eduAddressService.getById(house.getAddressId());
                    if (houseAdd != null ) {
                        if(houseAdd.getAddressTreeId()!=null&&addressTreeId!=null&&houseAdd.getAddressTreeId() - addressTreeId == 0) {
                            //树最终id一致默认为房户一致
                            fhyz = true;
                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                    .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                    .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                    .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                    .set(EduStudentEnrollPre::getConsistentRemarks, "在地址池中节点一致，比对通过");
                            eduStudentEnrollPreService.update(updateWrapper);
                            break;
                        }else{
                            //因房产地址和户籍地址规则不一致，目前按同个小区，或者路同一号  下面同一幢 同单元 同室来判断
                            String houseStr=houseAdd.getParentPath();//房产的标准化地址
                            String bzhHouse= houseAdd.getAddressName();
                            String haoHouse= houseAdd.getAddressName();
                            if(StringUtils.isNotBlank(houseStr)){
                                //去除中间路的xxx号
                                haoHouse=AddressUtil.extractHao(houseStr);
                                haoHouse=AddressUtil.extractBeforeFirstDigit(haoHouse);
                                bzhHouse=AddressUtil.extractBeforeFirstDigit(houseStr);
                            }
                            if(bzhHouse.equalsIgnoreCase(bzhHousehold)||haoHouse.equalsIgnoreCase(haoHousehold)){
                                if(houseAdd.getAddressTreeId()!=null&&houseHoldAdd.getAddressTreeId()!=null&&StringUtils.isNotBlank(houseAdd.getParentPath())&&StringUtils.isNotBlank(houseHoldAdd.getParentPath())){
                                    EduAddressTree householdTree=eduAddressTreeService.getById(houseHoldAdd.getAddressTreeId());
                                    EduAddressTree houseTree=eduAddressTreeService.getById(houseAdd.getAddressTreeId());
                                    if(householdTree!=null&&houseTree!=null){
                                        String hj="";
                                        String fc="";
                                        if(bzhHouse.equalsIgnoreCase(bzhHousehold)){
                                            hj=houseHoldAdd.getParentPath()+householdTree.getAreaName();
                                            fc=houseAdd.getParentPath()+houseTree.getAreaName();
                                        }else{
                                            hj=AddressUtil.extractHao(houseHoldAdd.getParentPath())+householdTree.getAreaName();
                                            fc=AddressUtil.extractHao(houseAdd.getParentPath())+houseTree.getAreaName();
                                        }

                                        String hjStr=hj.replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                        String fcStr=fc.replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                        if(StringUtils.isNotBlank(hjStr)){
                                            hjStr=hjStr.toUpperCase();
                                        }
                                        if(StringUtils.isNotBlank(fcStr)){
                                            fcStr=fcStr.toUpperCase();
                                        }
                                        if (StringUtils.isNotBlank(hjStr)&&hjStr.equals(fcStr)){
                                            fhyz = true;
                                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                    .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                    .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                    .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                    .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                            eduStudentEnrollPreService.update(updateWrapper);
                                            break;
                                        }else{
                                            if (fc.equalsIgnoreCase(hj)){
                                                fhyz = true;
                                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                        .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                        .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                        .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                                eduStudentEnrollPreService.update(updateWrapper);
                                                break;
                                            }
                                        }
                                    }else {
                                        //数字前面的标准化地址一致，截取所有数字来判断是否相同
                                        String hjStr=houseHoldAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                        String fcStr=houseAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                        if(StringUtils.isNotBlank(hjStr)){
                                            hjStr=hjStr.toUpperCase();
                                        }
                                        if(StringUtils.isNotBlank(fcStr)){
                                            fcStr=fcStr.toUpperCase();
                                        }
                                        if (StringUtils.isNotBlank(hjStr)&&hjStr.equals(fcStr)){
                                            fhyz = true;
                                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                    .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                    .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                    .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                    .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                            eduStudentEnrollPreService.update(updateWrapper);
                                            break;
                                        }
                                    }

                                }else{
                                    //数字前面的标准化地址一致，截取所有数字来判断是否相同
                                    String hjStr=houseHoldAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                    String fcStr=houseAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                    if(StringUtils.isNotBlank(hjStr)){
                                        hjStr=hjStr.toUpperCase();
                                    }
                                    if(StringUtils.isNotBlank(fcStr)){
                                        fcStr=fcStr.toUpperCase();
                                    }
                                    if (StringUtils.isNotBlank(hjStr)&&hjStr.equals(fcStr)){
                                        fhyz = true;
                                        updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                        eduStudentEnrollPreService.update(updateWrapper);
                                        break;
                                    }
                                }

                            }else{
                                //判断上级节点名称是否一致
                                if(StringUtils.isNotBlank(houseAdd.getStreetCode())&&houseAdd.getStreetCode().equalsIgnoreCase(houseHoldAdd.getStreetCode())){
                                    if(houseAdd.getAddressTreeId()!=null&&houseHoldAdd.getAddressTreeId()!=null&&StringUtils.isNotBlank(houseAdd.getParentPath())&&StringUtils.isNotBlank(houseHoldAdd.getParentPath())){
                                        EduAddressTree householdTree=eduAddressTreeService.getById(houseHoldAdd.getAddressTreeId());
                                        EduAddressTree houseTree=eduAddressTreeService.getById(houseAdd.getAddressTreeId());
                                        if(householdTree!=null&&houseTree!=null){
                                            String hj=houseHoldAdd.getParentPath()+householdTree.getAreaName();
                                            String fc=houseAdd.getParentPath()+houseTree.getAreaName();
                                            String hjStr=hj.replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                            String fcStr=fc.replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                            if(StringUtils.isNotBlank(hjStr)){
                                                hjStr=hjStr.toUpperCase();
                                            }
                                            if(StringUtils.isNotBlank(fcStr)){
                                                fcStr=fcStr.toUpperCase();
                                            }
                                            if (StringUtils.isNotBlank(hjStr)&&hjStr.equals(fcStr)){
                                                fhyz = true;
                                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                        .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                        .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                        .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                                eduStudentEnrollPreService.update(updateWrapper);
                                                break;
                                            }else{
                                                if (fc.equalsIgnoreCase(hj)){
                                                    fhyz = true;
                                                    updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                            .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                            .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                            .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                            .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                                    eduStudentEnrollPreService.update(updateWrapper);
                                                    break;
                                                }
                                            }
                                        }else {
                                            //数字前面的标准化地址一致，截取所有数字来判断是否相同
                                            String hjStr=houseHoldAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                            String fcStr=houseAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                            if(StringUtils.isNotBlank(hjStr)){
                                                hjStr=hjStr.toUpperCase();
                                            }
                                            if(StringUtils.isNotBlank(fcStr)){
                                                fcStr=fcStr.toUpperCase();
                                            }
                                            if (StringUtils.isNotBlank(hjStr)&&hjStr.equals(fcStr)){
                                                fhyz = true;
                                                updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                        .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                        .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                        .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                        .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                                eduStudentEnrollPreService.update(updateWrapper);
                                                break;
                                            }
                                        }

                                    }else{
                                        //数字前面的标准化地址一致，截取所有数字来判断是否相同
                                        String hjStr=houseHoldAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                        String fcStr=houseAdd.getAddressName().replaceAll("[^0-9]", "").replaceFirst("^0+(?!$)", "");
                                        if(StringUtils.isNotBlank(hjStr)){
                                            hjStr=hjStr.toUpperCase();
                                        }
                                        if(StringUtils.isNotBlank(fcStr)){
                                            fcStr=fcStr.toUpperCase();
                                        }
                                        if (StringUtils.isNotBlank(hjStr)&&hjStr.equals(fcStr)){
                                            fhyz = true;
                                            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "1")
                                                    .set(EduStudentEnrollPre::getHouseId, house.getHouseId())
                                                    .set(EduStudentEnrollPre::getBeforeFlag,"0")
                                                    .set(EduStudentEnrollPre::getHouseholdId, household.getHouseholdId())
                                                    .set(EduStudentEnrollPre::getConsistentRemarks, "程序通过模糊匹配认为一致，比对通过");
                                            eduStudentEnrollPreService.update(updateWrapper);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
            }
            if (fhyz) {
                pre.setConsistentFlag("1");
                return;
            }

            updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag, "2")
                    .set(EduStudentEnrollPre::getHouseholdId,null)
                    .set(EduStudentEnrollPre::getHouseId,null)
                    .set(EduStudentEnrollPre::getBeforeFlag,"0")
                    .set(EduStudentEnrollPre::getConsistentRemarks, "房产和户籍地址不一致，比对不通过");
            eduStudentEnrollPreService.update(updateWrapper);
            pre.setConsistentFlag("2");
            return;
        }
    }
    private void setSyncIrs(String body,List<EduSyncIrs> list){
        if(StringUtils.isNotBlank(body)){
            AppResponse appResponse= JSON.parseObject(body,AppResponse.class);
            if(appResponse.getCode()==0){
                for(EduSyncIrs eduSyncIrs:list){
                    eduSyncIrs.setSendFlag(BoolEnum.TRUE.getType());
                    eduSyncIrs.setSendTime(new Date());
                    eduSyncIrs.setSendErrorCnt(0);
                    eduSyncIrs.setSendMsg("成功");
                }
            }else{
                for(EduSyncIrs eduSyncIrs:list){
                    eduSyncIrs.setSendFlag("2");
                    eduSyncIrs.setSendTime(new Date());
                    if(eduSyncIrs.getSendErrorCnt()==null){
                        eduSyncIrs.setSendErrorCnt(1);
                    }else{
                        eduSyncIrs.setSendErrorCnt(eduSyncIrs.getSendErrorCnt()+1);
                    }
                    if(StringUtils.isNotBlank(appResponse.getMessage())){
                        if(appResponse.getMessage().length()>300){
                            eduSyncIrs.setSendMsg(appResponse.getMessage().substring(0,200));
                        }else{
                            eduSyncIrs.setSendMsg(appResponse.getMessage());
                        }

                    }else{
                        eduSyncIrs.setSendMsg("发送失败");
                    }

                }
            }
            eduSyncIrsService.updateBatchById(list);
        }
    }
    private Integer checkAreaCode(AreaControlVO vo){
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        if(StringUtils.isBlank(vo.getAreaCode())){
            throw new AppException("请传入需要批量处理数据的统筹区");
        }
        if (vo.getFlag() == null) {
            vo.setFlag(true);
        }
        EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
        queryVO.setOperating("YW002");
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setClassify("2");
        EduOperationCacheDetailVO bmOption=eduSystemConfigIntegration.getEduOperationOne(queryVO);
        //校验是否可以大数据获取
        if (vo.getFlag() && bmOption != null) {
            if(bmOption.isFlag()){
                throw new AppException(bmOption.getYear()+"年度报名已开始，不能批量获取大数据");
            }else if(bmOption.getType().equalsIgnoreCase("2")){
                throw new AppException(bmOption.getYear()+"年度报名已结束，不能批量获取大数据");
            }

        }
        return bmOption==null? DateUtil.thisYear():bmOption.getYear();
    }
    private void syncHj(String body){
        if(StringUtils.isNotBlank(body)){
            AppResponse appResponse= JSON.parseObject(body,AppResponse.class);
            if(appResponse.getCode()!=0){
                return ;
            }
            if (appResponse.getResult()==null){
                return ;
            }
            EduSyncIrsVO irsData= JSON.parseObject(JSON.toJSONString(appResponse.getResult()),EduSyncIrsVO.class);
            irsData.setSendFlag(BoolEnum.TRUE.getType());
            EduSyncIrs eduSyncIrs=eduSyncIrsService.getById(irsData.getIrsSyncId());
            if (eduSyncIrs==null){
                return ;
            }
            String resParams= irsData.getResParams();
            eduSyncIrs.setResParams(resParams);
            eduSyncIrs.setIrsSendMsg(irsData.getIrsSendMsg());
            eduSyncIrs.setIrsSendErrorCnt(irsData.getIrsSendErrorCnt());
            eduSyncIrs.setIrsSendTime(irsData.getIrsSendTime());
            eduSyncIrs.setIrsSendFlag(irsData.getIrsSendFlag());
            if(BoolEnum.TRUE.getType().equalsIgnoreCase(irsData.getIrsSendFlag())&&StringUtils.isNotBlank(resParams)){
                JSONArray jsonArray=JSONArray.parseArray(resParams);
                if (jsonArray != null && jsonArray.size() > 0) {
                    jsonArray.forEach(
                            item -> {
                                JSONObject personData = (JSONObject) item;
                                EduHouseHoldInterfaceVO holdInterfaceVO =
                                        personData
                                                .getJSONObject("ELC_LICENCE_STRUCT")
                                                .getObject("DATA", EduHouseHoldInterfaceVO.class);
                                String elcLicenceName = (String) personData.get("ELC_LICENCE_NAME");
                                holdInterfaceVO.setElcLicenceName(elcLicenceName);
                                QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                                householdQueryWrapper
                                        .lambda()
                                        .eq(EduHousehold::getYear, eduSyncIrs.getYear())
                                        .eq(EduHousehold::getIdcard, holdInterfaceVO.getCZRKGMSFHM());

                                List<EduHousehold> oldList =
                                        eduHouseholdService.list(householdQueryWrapper);
                                if (!CollectionUtils.isEmpty(oldList)) {
                                    List<String> idList = oldList.stream()
                                            .map(EduHousehold::getHouseholdId)
                                            .collect(Collectors.toList());
                                    eduHouseholdService.removeByIds(idList);
                                }
                                EduHousehold eduHousehold = new EduHousehold();
                                eduHousehold.setHouseholdId(IdUtil.simpleUUID());
                                eduHousehold.setHhid(holdInterfaceVO.getCZRKHHID());
                                eduHousehold.setHh(holdInterfaceVO.getCZRKHH());
                                eduHousehold.setIdcard(holdInterfaceVO.getCZRKGMSFHM());
                                eduHousehold.setFullName(holdInterfaceVO.getCZRKXM());
                                eduHousehold.setAddress(holdInterfaceVO.getCZRKZZ());
                                eduHousehold.setBirthday(holdInterfaceVO.getCZRKCSRQ());
                                eduHousehold.setSex(holdInterfaceVO.getCZRKXB());
                                eduHousehold.setCountry(holdInterfaceVO.getCZRKJGGJ());
                                eduHousehold.setBirthplace(holdInterfaceVO.getCZRKCSDSSX());
                                eduHousehold.setNativePlace(holdInterfaceVO.getCZRKJGSSX());
                                eduHousehold.setHouseholdPlace(holdInterfaceVO.getCZRKZZ());
                                eduHousehold.setAccountType(holdInterfaceVO.getElcLicenceName());
                                eduHousehold.setRelation(holdInterfaceVO.getCZRKYHZGX());
                                eduHousehold.setHouseholder(holdInterfaceVO.getCZRKHZXM());
                                eduHousehold.setServiceSpaces(holdInterfaceVO.getCZRKFWCS());
                                eduHousehold.setHsqlbz(holdInterfaceVO.getCZRKHSQLBS());
                                eduHousehold.setHssqlbz(holdInterfaceVO.getCZRKHZQLSSX());
                                eduHousehold.setHssqxqlws(holdInterfaceVO.getCZRKHDQLXZ());
                                eduHousehold.setHxzlbd(holdInterfaceVO.getCZRKHZQLXZ());
                                eduHousehold.setHsqlbs(holdInterfaceVO.getCZRKHZQLSSX());
                                if (eduHousehold.getAddress().indexOf("东阳") >= 0) {
                                    //地址中包含东阳的就认为是东阳市地址
                                    eduHousehold.setAreaCode("330783");
                                }
                                if (StringUtils.isNotBlank(holdInterfaceVO.getCZRKHSQLBZ())) {
                                    try {
                                        if (holdInterfaceVO.getCZRKHSQLBZ().length() == 8) {
                                            eduHousehold.setRegistrationDate(DatePattern.PURE_DATE_FORMAT.parse(holdInterfaceVO.getCZRKHSQLBZ()));
                                        } else if (holdInterfaceVO.getCZRKHSQLBZ().length() == 10) {
                                            eduHousehold.setRegistrationDate(DatePattern.NORM_DATE_FORMAT.parse(holdInterfaceVO.getCZRKHSQLBZ()));
                                        }
                                    } catch (Exception e) {
                                        log.error("户籍迁入时间格式转换异常"+e.getMessage());
                                    }

                                }
                                eduHousehold.setAuthStatus(AuthStatusEnum.YES.getType());
                                eduHousehold.setStatus(BoolEnum.TRUE.getType());
                                String yearString = Integer.toString(eduSyncIrs.getYear());
                                eduHousehold.setYear(yearString);
                                String bnxxFlag="0";
                                String bnczFlag="0";
                                if(StringUtils.isNotBlank(eduSyncIrs.getStudentEnrollPreId())){
                                    EduStudentEnrollPre eduStudentEnrollPre=eduStudentEnrollPreService.getById(eduSyncIrs.getStudentEnrollPreId());
                                    if(eduStudentEnrollPre!=null){
                                        if(SchoolCategoryEnum.PRIMARY.getType().equals(eduStudentEnrollPre.getSchoolCategory())){
                                            bnxxFlag="1";
                                        }
                                        if(SchoolCategoryEnum.JUNIOR.getType().equals(eduStudentEnrollPre.getSchoolCategory())){
                                            bnczFlag="1";
                                        }
                                    }
                                }
                                String addressId =
                                        eduAddressService.saveByAddress(eduHousehold.getAddress(),Integer.parseInt(eduHousehold.getYear()),bnxxFlag,bnczFlag);
                                eduHousehold.setAddressId(addressId);
                                eduHouseholdService.saveOrUpdate(eduHousehold);
                            });
                } else {
                    QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                    householdQueryWrapper
                            .lambda()
                            .eq(EduHousehold::getIdcard, eduSyncIrs.getDataId())
                            .eq(EduHousehold::getYear, eduSyncIrs.getYear());
                    List<EduHousehold> oldList =
                            eduHouseholdService.list(householdQueryWrapper);
                    if (!CollectionUtils.isEmpty(oldList)) {
                        List<String> idList = oldList.stream()
                                .map(EduHousehold::getHouseholdId)
                                .collect(Collectors.toList());
                        eduHouseholdService.removeByIds(idList);
                    }
                }
            }
            eduSyncIrs.setSyncTime(new Date());
            if(BoolEnum.TRUE.getType().equalsIgnoreCase(irsData.getIrsSendFlag())){
                eduSyncIrs.setSyncStatus(BoolEnum.TRUE.getType());
                eduSyncIrs.setSyncMsg("同步成功");
                eduSyncIrsService.updateById(eduSyncIrs);
                UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,eduSyncIrs.getStudentEnrollPreId())
                        .set(EduStudentEnrollPre::getHouseholdSyncFlag,BoolEnum.TRUE.getType())
                        .set(EduStudentEnrollPre::getHouseholdSyncRemark,irsData.getIrsSendMsg());
                EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(eduSyncIrs.getStudentEnrollPreId());
                if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                    //人工处理过的数据，不重新比对
                    updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                            .set(EduStudentEnrollPre::getHouseholdId,null);
                }
                eduStudentEnrollPreService.update(updateWrapper);
            }else if("2".equalsIgnoreCase(irsData.getIrsSendFlag())){
                UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,eduSyncIrs.getStudentEnrollPreId())
                        .set(EduStudentEnrollPre::getHouseholdSyncFlag,"2")
                        .set(EduStudentEnrollPre::getHouseholdSyncRemark,irsData.getIrsSendMsg());
                EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(eduSyncIrs.getStudentEnrollPreId());
                if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                    //人工处理过的数据，不重新比对
                    updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                            .set(EduStudentEnrollPre::getHouseholdId,null);
                }
                eduStudentEnrollPreService.update(updateWrapper);
            }
        }
    }
    private void syncJzz(String body){
        if(StringUtils.isNotBlank(body)){
            AppResponse appResponse= JSON.parseObject(body,AppResponse.class);
            if(appResponse.getCode()!=0){
                return ;
            }
            if (appResponse.getResult()==null){
                return ;
            }
            EduSyncIrsVO irsData= JSON.parseObject(JSON.toJSONString(appResponse.getResult()),EduSyncIrsVO.class);
            irsData.setSendFlag(BoolEnum.TRUE.getType());
            EduSyncIrs eduSyncIrs=eduSyncIrsService.getById(irsData.getIrsSyncId());
            if (eduSyncIrs==null){
                return ;
            }
            String resParams= irsData.getResParams();
            eduSyncIrs.setResParams(resParams);
            eduSyncIrs.setIrsSendMsg(irsData.getIrsSendMsg());
            eduSyncIrs.setIrsSendErrorCnt(irsData.getIrsSendErrorCnt());
            eduSyncIrs.setIrsSendTime(irsData.getIrsSendTime());
            eduSyncIrs.setIrsSendFlag(irsData.getIrsSendFlag());
            List<DyJzzVO> jzzVOList = new ArrayList<>();
            if(BoolEnum.TRUE.getType().equalsIgnoreCase(irsData.getIrsSendFlag())&&StringUtils.isNotBlank(resParams)){
                JSONArray jsonArray=JSONArray.parseArray(resParams);
                if (jsonArray != null && jsonArray.size() > 0) {
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JSONObject dataAll = jsonArray.getJSONObject(i);
                        JSONObject dataS = dataAll.getJSONObject("ELC_LICENCE_STRUCT");
                        JSONObject data=dataS.getJSONObject("DATA");
                        DyJzzVO jzzVO = new DyJzzVO();
                        jzzVO.setSfzh(data.getString("SFZH"));
                        jzzVO.setXm(data.getString("XM"));
                        jzzVO.setXb(data.getString("XB"));
                        jzzVO.setZjnbbh(data.getString("ZJNBBH"));
                        jzzVO.setZjzt(data.getString("ZJZT"));
                        jzzVO.setMz(data.getString("MZ"));
                        jzzVO.setQzrq(data.getString("FZRQ"));
                        jzzVO.setFzdgajg(data.getString("FZDGAJG"));
                        if(jzzVO.getFzdgajg().indexOf("东阳")>=0) {
                            jzzVO.setXzqhdm("330783");
                            jzzVO.setAreaCode(jzzVO.getXzqhdm());
                            jzzVOList.add(jzzVO);
                        }

                    }
                }
                QueryWrapper<EduLivePlace> livePlaceQueryWrapper = new QueryWrapper<>();
                livePlaceQueryWrapper
                        .lambda()
                        .eq(EduLivePlace::getSourceType, SourceTypeEnum.gx.getType())
                        .eq(EduLivePlace::getSfzh, eduSyncIrs.getDataId())
                        .eq(EduLivePlace::getYear, eduSyncIrs.getYear());


                List<EduLivePlace> oldList = eduLivePlaceService.list(livePlaceQueryWrapper);



                if (CollectionUtils.isEmpty(jzzVOList)) {
                    if (!CollectionUtils.isEmpty(oldList)) {
                        eduLivePlaceService.removeByIds(
                                oldList.stream()
                                        .map(EduLivePlace::getLivePlaceId)
                                        .collect(Collectors.toList()));
                    }
                    return ;
                }
                List<EduLivePlace> livePlaceList = Convert.toList(EduLivePlace.class, jzzVOList);
                livePlaceList.forEach(
                        item -> {
                            item.setLivePlaceId(IdUtil.simpleUUID());
                            if (!CollectionUtils.isEmpty(oldList)) {
                                for (EduLivePlace eduLivePlace : oldList) {
                                    if (eduLivePlace.getZjnbbh().equalsIgnoreCase(item.getZjnbbh())) {
                                        item.setLivePlaceId(eduLivePlace.getLivePlaceId());
                                        break;
                                    }
                                }
                            }
                            item.setYear(eduSyncIrs.getYear());
                            item.setAreaCode(item.getFzdgajgdm());
                            item.setSourceType(SourceTypeEnum.gx.getType());
                        });
                if (!CollectionUtils.isEmpty(oldList)) {
                    for (EduLivePlace old : oldList) {
                        boolean flag = true;
                        for (EduLivePlace newPlace : livePlaceList) {
                            if (newPlace.getZjnbbh().equalsIgnoreCase(old.getZjnbbh())) {
                                flag = false;
                            }
                        }
                        if (flag) {
                            eduLivePlaceService.removeById(old.getLivePlaceId());
                        }
                    }
                }
                eduLivePlaceService.saveOrUpdateBatch(livePlaceList);
            }
            eduSyncIrs.setSyncTime(new Date());
            if(BoolEnum.TRUE.getType().equalsIgnoreCase(irsData.getIrsSendFlag())){
                eduSyncIrs.setSyncStatus(BoolEnum.TRUE.getType());
                eduSyncIrs.setSyncMsg("同步成功");
                eduSyncIrsService.updateById(eduSyncIrs);
                UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,eduSyncIrs.getStudentEnrollPreId())
                        .set(EduStudentEnrollPre::getHouseholdSyncFlag,BoolEnum.TRUE.getType())
                        .set(EduStudentEnrollPre::getHouseholdSyncRemark,irsData.getIrsSendMsg());
                EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(eduSyncIrs.getStudentEnrollPreId());
                if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                    //人工处理过的数据，不重新比对
                    updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                            .set(EduStudentEnrollPre::getHouseholdId,null);
                }
                eduStudentEnrollPreService.update(updateWrapper);
            }else if("2".equalsIgnoreCase(irsData.getIrsSendFlag())){
                UpdateWrapper<EduStudentEnrollPre> updateWrapper=new UpdateWrapper<>();
                updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId,eduSyncIrs.getStudentEnrollPreId())
                        .set(EduStudentEnrollPre::getHouseholdSyncFlag,"2")
                        .set(EduStudentEnrollPre::getHouseholdSyncRemark,irsData.getIrsSendMsg());
                EduStudentEnrollPre pre=eduStudentEnrollPreService.getById(eduSyncIrs.getStudentEnrollPreId());
                if(pre!=null&&!"2".equalsIgnoreCase(pre.getConsistentType())){
                    //人工处理过的数据，不重新比对
                    updateWrapper.lambda().set(EduStudentEnrollPre::getConsistentFlag,BoolEnum.FALSE.getType())
                            .set(EduStudentEnrollPre::getHouseholdId,null);
                }
                eduStudentEnrollPreService.update(updateWrapper);
            }
        }
    }
    @Override
    @OpApi(funcCode = "eduStudentEnrollBefore0025", title = "预报名管理重新比对房产一致", funcType = FuncTypeEnum.other)
    public void getFcyz(EduStudentEnrollPreKeyVO vo) {
        if(StringUtils.isBlank(vo.getStudentEnrollPreId())){
            throw new AppException("预报名id不能为空");
        }
        EduStudentEnrollPre eduStudentEnrollPre=eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        if(eduStudentEnrollPre==null){
            throw new AppException("未找到预采集信息");
        }
        if("2".equalsIgnoreCase(eduStudentEnrollPre.getConsistentType())){
            throw new AppException("已做过人工核对房户一致，不能自动比对");
        }
        this.fhyzTaskDg(eduStudentEnrollPre);
    }

    @Override
    public void getBatchJfmx(AreaControlVO vo) {
        String redisKey= EduCache.EDU_BATCH_handle+"getCbjfmx";
        if(redisHelper.hasKey(redisKey)){
            throw new AppException("正在比对中...");
        }
        Integer year=eduHelper.thisYear();
        if(StringUtils.isBlank(vo.getAreaCode())){
            vo.setAreaCode(eduHelper.thisAreaCode());
        }
        DictAreaVO dictAreaVO = new DictAreaVO();
        dictAreaVO.setParentId(vo.getAreaCode());
        dictAreaVO.setPermissionFlag(false);
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(dictAreaVO);
        List<String> areaList =new ArrayList<>();
        if (!CollectionUtils.isEmpty(districtByOrg)){
            areaList=districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
            if(areaList.contains("330701")){
                areaList.add("330799");
            }
        }else{
            areaList.add(vo.getAreaCode());
            if (vo.getAreaCode().equalsIgnoreCase("330701")){
                areaList.add("330799");
            }
        }
        List<String> aae140List=new ArrayList<>();
        aae140List.add("110");
        aae140List.add("120");
        LambdaQueryWrapper<EduSocialSecurity> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(EduSocialSecurity::getYear,year)
                .in(EduSocialSecurity::getAae140,aae140List)
                .in(EduSocialSecurity::getAab301,areaList)
                .eq(EduSocialSecurity::getAac008,"1")
                .eq(EduSocialSecurity::getAac031,"1")
                .eq(EduSocialSecurity::getTotalFlag,"0")
                .last("limit 1000");
        List<EduSocialSecurity> list=eduSocialSecurityService.list(queryWrapper);
        if(!CollectionUtils.isEmpty(list)){
            ApiModel apiModel=eduHelper.getEduFunc("saveCbJfInterfaceData",vo.getAreaCode());
            redisHelper.set(redisKey,"参保批量获取正在执行中",1200);
            try {
                Object bean = ApplicationContextHelper.getBean(apiModel.getBeanName());
                if (null != bean) {

                    for(EduSocialSecurity item:list){
                        try {
                            apiModel.getMethod().invoke(bean, item,vo.getReqIp());
                        } catch (Exception e) {
                            log.error("大数据社保获取异常："+e.getMessage());
                        }
                    }
                }else {
                    throw new AppException(vo.getAreaCode()+"未找到处理我的报名的个性化方法");
                }
            }catch (AppException e ){
                throw e;
            }catch (Exception e ){
                throw new AppException( e.getMessage(),e);
            }finally {
                redisHelper.del(redisKey);
            }
        }
    }
}
